﻿using System;
using System.Collections;
using System.Collections.Generic;
using WindowsPhoneEssentials.Abstractions;

namespace WindowsPhoneEssentials.Testing.Abstractions
{
    public class FakeIsolatedStorageSettings : IIsolatedStorageSettings
    {
        private readonly Dictionary<string, object> settings;

        public FakeIsolatedStorageSettings()
        {
            settings = new Dictionary<string, object>();
        }

        public int Count
        {
            get { return settings.Count; }
        }

        public ICollection Keys
        {
            get { return settings.Keys; }
        }

        public ICollection Values
        {
            get { return settings.Values; }
        }

        public object this[string key]
        {
            get { return settings[key]; }
            set { settings[key] = value; }
        }

        public void Add(string key, object value)
        {
            settings.Add(key, value);
        }

        public void Clear()
        {
            settings.Clear();
        }

        public bool ContainsKey(string key)
        {
            return settings.ContainsKey(key);
        }

        public bool Remove(string key)
        {
            return settings.Remove(key);
        }

        public void Save()
        {
        }

        public bool TryGetValue<T>(string key, out T value)
        {
            object tmp;
            var result = settings.TryGetValue(key, out tmp);
            value = (T) tmp;
            return result;
        }

        ICollection<string> IDictionary<string, object>.Keys
        {
            get { throw new InvalidOperationException(); }
        }

        ICollection<object> IDictionary<string, object>.Values
        {
            get { throw new InvalidOperationException(); }
        }

        bool ICollection<KeyValuePair<string, object>>.IsReadOnly
        {
            get { throw new InvalidOperationException(); }
        }

        bool IDictionary<string, object>.TryGetValue(string key, out object value)
        {
            throw new InvalidOperationException();
        }

        void ICollection<KeyValuePair<string, object>>.Add(KeyValuePair<string, object> item)
        {
            throw new InvalidOperationException();
        }

        void ICollection<KeyValuePair<string, object>>.Clear()
        {
            throw new InvalidOperationException();
        }

        bool ICollection<KeyValuePair<string, object>>.Contains(KeyValuePair<string, object> item)
        {
            throw new InvalidOperationException();
        }

        void ICollection<KeyValuePair<string, object>>.CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
        {
            throw new InvalidOperationException();
        }

        bool ICollection<KeyValuePair<string, object>>.Remove(KeyValuePair<string, object> item)
        {
            throw new InvalidOperationException();
        }

        IEnumerator<KeyValuePair<string, object>> IEnumerable<KeyValuePair<string, object>>.GetEnumerator()
        {
            throw new InvalidOperationException();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            throw new InvalidOperationException();
        }
    }
}
